package com.magic.blog.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.magic.blog.entity.MComment;
import com.magic.blog.entity.MUserMessage;
import com.magic.blog.service.*;
import com.magic.blog.shiro.AccountProfile;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * created by mzk on 2020/07/24
 */
public class BaseController {
    @Autowired
    HttpServletRequest request;

    @Autowired
    MPostService postService;

    @Autowired
    MCommentService commentService;

    @Autowired
    MUserService userService;

    @Autowired
    MUserMessageService messageService;

    @Autowired
    MUserCollectionService collectionService;

    @Autowired
    MCategoryService categoryService;

    public Page getPage() {
        int pn = ServletRequestUtils.getIntParameter(request, "pn", 1);
        int size = ServletRequestUtils.getIntParameter(request, "size", 2);

        return new Page(pn, size);
    }

    protected AccountProfile getProfile(){
        return (AccountProfile) SecurityUtils.getSubject().getPrincipal();
    }
    protected Long getProfileId(){
        return getProfile().getId();
    }
}
